home *** CD-ROM | disk | FTP | other *** search
- /*
- ReadLuminanceRecord.c
- 7/29/91 dgp
- Reads a LuminanceRecord?.h file at runtime. In the past these calibration-data files
- could only be used by #including them at compile time.
-
- All heap allocations in ReadLuminanceRecord are temporary, recovered before returning.
- However, it calls ReadAssignmentFile(), which allocates space for each string. This space
- may be recovered by calling free() for each string.
-
- HISTORY:
- 8/24/91 dgp Made compatible with THINK C 5.0.
- Preserve default values of LP->VMin and LP->VMax if no new values are read.
- 8/26/91 dgp Rewrote using new SetVariable() routine, which makes the code easier to
- read.
- 12/17/92 dgp Added dacSize.
- 12/21/92 dgp Changed type of dacSize from long to short.
- */
-
- #include "VideoToolbox.h"
- #include "Luminance.h"
- #define VARIABLES 51L /* only 47 are used at present */
-
- #if 0
- void main()
- {
- static luminanceRecord LR,LR2;
-
- #include "LuminanceRecord1.h"
- ReadLuminanceRecord("LuminanceRecord1.h",&LR2,echoAssignments+echoComments+echoFile);
- /* You can use the THINK C debugger to compare LR and LR2, which should be
- identical in content. */
- }
- #endif
-
- int ReadLuminanceRecord(char *filename,luminanceRecord *LP,int echo)
- {
- Variable *p,*p0;
- int i,j,k=0,n;
- double VMin,VMax;
- void **allocation;
-
- /* get default values */
- VMin=LP->VMin;
- VMax=LP->VMax;
-
- p0=p=(Variable *)malloc(VARIABLES*sizeof(Variable));
- allocation=(void **)malloc(VARIABLES*sizeof(void *));
- if(p==NULL || allocation==NULL){
- noRoom:
- PrintfExit("\nReadLuminanceRecord: no room for temporary storage\n\007");
- }
-
- /* Create a structure describing the variables. */
- j=0;
- p[j++]=SetVariable(shortType,&LP->dacSize,"LR.dacSize");
- p[j++]=SetVariable(doubleType,&LP->LMin,"LR.LMin");
- p[j++]=SetVariable(doubleType,&LP->LMax,"LR.LMax");
- p[j++]=SetVariable(doubleType,&LP->LBackground,"LR.LBackground");
- p[j++]=SetVariable(shortType,&LP->VBackground,"LR.VBackground");
- p[j++]=SetVariable(shortType,&LP->screen,"LR.screen");
- p[j++]=SetVariable(stringType,&LP->id,"LR.id");
- p[j++]=SetVariable(stringType,&LP->name,"LR.name");
- p[j++]=SetVariable(stringType,&LP->date,"LR.date");
- p[j++]=SetVariable(stringType,&LP->notes,"LR.notes");
- p[j++]=SetVariable(doubleType,&LP->dpi,"LR.dpi");
- p[j++]=SetVariable(doubleType,&LP->Hz,"LR.Hz");
- p[j++]=SetVariable(stringType,&LP->units,"LR.units");
- p[j++]=SetVariable(longType,&LP->coefficients,"LR.coefficients");
- for(i=0;i<sizeof(LP->p)/sizeof(LP->p[0]);i++){
- p[j]=SetVariable(doubleType,&LP->p[i],allocation[k++]=malloc(16));
- if(p[j].name==NULL)goto noRoom;
- sprintf(p[j++].name,"LR.p[%d]",i);
- }
- p[j++]=SetVariable(doubleType,&LP->polynomialError,"LR.polynomialError");
- for(i=0;i<sizeof(LP->q)/sizeof(LP->q[0]);i++){
- p[j]=SetVariable(doubleType,&LP->q[i],allocation[k++]=malloc(16));
- if(p[j].name==NULL)goto noRoom;
- sprintf(p[j++].name,"LR.q[%d]",i);
- }
- p[j++]=SetVariable(doubleType,&LP->quadraticError,"LR.quadraticError");
- for(i=0;i<sizeof(LP->power)/sizeof(LP->power[0]);i++){
- p[j]=SetVariable(doubleType,&LP->power[i],allocation[k++]=malloc(16));
- if(p[j].name==NULL)goto noRoom;
- sprintf(p[j++].name,"LR.power[%d]",i);
- }
- p[j++]=SetVariable(doubleType,&LP->powerError,"LR.powerError");
- for(i=0;i<sizeof(LP->fixedPower)/sizeof(LP->fixedPower[0]);i++){
- p[j]=SetVariable(doubleType,&LP->fixedPower[i],allocation[k++]=malloc(32));
- if(p[j].name==NULL)goto noRoom;
- sprintf(p[j++].name,"LR.fixedPower[%d]",i);
- }
- p[j++]=SetVariable(doubleType,&LP->fixedPowerError,"LR.fixedPowerError");
- p[j++]=SetVariable(doubleType,&LP->r,"LR.r");
- p[j++]=SetVariable(doubleType,&LP->g,"LR.g");
- p[j++]=SetVariable(doubleType,&LP->b,"LR.b");
- p[j++]=SetVariable(doubleType,&LP->gainAccuracy,"LR.gainAccuracy");
- p[j++]=SetVariable(doubleType,&LP->gm,"LR.gm");
- p[j++]=SetVariable(shortType,&LP->rangeSet,"LR.rangeSet");
- p[j++]=SetVariable(shortType,&LP->L.exists,"LR.L.exists");
- /*
- Special handling is required for LR.VMin and LR.VMax, which used to be doubles but
- are now shorts. They are assigned floating point values 0.0 and 255.0 in
- old LuminanceRecord files, and are assigned short values 0 and 255 in
- newer LuminanceRecord files. ReadAssignmentFile() won't do type conversion.
- To handle both flavors we read LR.VMin and LR.VMax into
- temporary double variables before converting them to shorts.
- */
- p[j++]=SetVariable(doubleType,&VMin,"LR.VMin");
- p[j++]=SetVariable(doubleType,&VMax,"LR.VMax");
- p[j++]=SetVariable(0,NULL,NULL); /* Mark end of list */
- if(j>VARIABLES){
- PrintfExit("ReadLuminanceRecord: Oops. I used more variables than I allocated."
- " %ld>%ld\n\007",(long)j,VARIABLES);
- }
- n=ReadAssignmentFile(filename,p0,echo);
- LP->VMin=VMin;
- LP->VMax=VMax;
- free(p);
- for(i=0;i<k;i++)free(allocation[i]);
- return n;
- }
-